home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_400
/
436_01
/
inintgr.c
< prev
next >
Wrap
Text File
|
1994-10-07
|
6KB
|
278 lines
/*************************************************************************
Source file: ININTGR.C
INCON integer input handler.
Compiler: Borland Turbo C 2.01
INCON source files and the object and library files created from
them are:
Copyright (c) 1993-94, Richard Zigler.
You may freely distribute unmodified source, object, and library
files, and incorporate them into your own non-commercial software,
provided that this paragraph and the program name and copyright
strings defined in INCON.C are included in all copies.
*************************************************************************/
#include <conio.h>
#include <ctype.h>
#include <string.h>
#include "indefs.h" /* globals and definitions */
#include "incon.h" /* state definitions */
#include "indecl.h" /* public utility routines */
int pascal hIntegerField( STATES State, register int Pos )
{
register int s_ptr;
int max_length = StrLength - 1,
max_width = Width - 1;
switch( State )
{
case stError:
break;
case stQuit: /* [Enter] -- end input */
if ( StrLength < Prec )
Chr = -1;
else if ( !(Chr == K_PLUS || Chr == K_MINUS) )
Chr = 0;
More = NO;
break;
case stInit: /* field initialization */
if ( !Flags.Justify ) /* right justify default */
Flags.Justify = RJUST;
/****
If the first character is a sign, force signed input and
truncate the string at the first occurence of any other
non-digit character.
****/
Pos = 0;
if ( *OutStr == '+' || *OutStr == '-' )
{
Flags.Sign = YES;
++Pos;
}
while ( Pos < StrLength && isdigit( OutStr[Pos] ) )
++Pos;
OutStr[Pos] = '\0';
StrLength = Pos;
Pos = 0;
return ( Pos );
case stFieldClear: /* [Esc] -- clear field or exit */
if ( EscSet || *OutStr == '\0' )
More = NO;
else
{
Pos = StrLength = 0;
*OutStr = '\0';
++Update;
}
break;
case stDeleteCharLeft: /* [Backspace] -- delete left */
if ( Pos )
{
if ( Pos > max_length )
{
putch( BS );
putch( Fill );
OutStr[--Pos] = '\0';
--StrLength;
--Move;
}
else if ( Pos == max_length )
goto __TruncateAtCursor;
else
{
--Pos;
goto __MoveCharsToCursor;
}
}
break;
case stMoveToStart: /* [Home] -- start of field */
if ( Pos )
{
Pos = 0;
--Move;
}
break;
case stMoveCharLeft: /* [Left Arrow] -- move char lt */
if ( Pos )
{
--Pos;
--Move;
}
break;
case stMoveCharRight: /* [Right Arrow] -- move char rt */
if ( Pos < StrLength && Pos < max_width )
{
++Pos;
++Move;
}
break;
case stMoveToEnd: /* [End] -- end of field */
if ( Pos < StrLength && Pos < max_width )
{
Pos = StrLength;
++Move;
}
break;
case stMoveWordLeft: /* [Ctrl Left] -- move word lt */
if ( Pos )
{
Pos = WordLeft( Pos, OutStr, ' ' );
--Move;
}
break;
case stMoveWordRight: /* [Ctrl Right] -- move word rt */
if ( Pos < StrLength && Pos < max_width )
{
Pos = WordRight( Pos, OutStr, ' ' );
++Move;
}
break;
case stDeleteWordLeft: /* [Ctrl L] -- delete word left */
if ( Pos )
{
s_ptr = Pos;
Pos = WordLeft( Pos, OutStr, ' ' );
goto __DeleteWord;
}
break;
case stDeleteWordRight: /* [Ctrl R] -- delete word right */
if ( Pos < StrLength )
{
s_ptr = WordRight( Pos, OutStr, ' ' );
__DeleteWord:
;
memcpy( OutStr + Pos, OutStr + s_ptr, StrLength - s_ptr + 1 );
StrLength -= (s_ptr - Pos);
++Update;
}
break;
case stDeleteToEnd: /* [Ctrl End] -- clear to end */
if ( Pos < StrLength )
goto __TruncateAtCursor;
break;
case stDeleteToStart: /* [Ctrl Home] -- clear to start */
if ( Pos )
{
memcpy( OutStr, OutStr + Pos, StrLength - Pos + 1 );
StrLength -= Pos;
Pos = 0;
++Update;
}
break;
case stDeleteAtCursor: /* [Del] -- delete at cursor */
if ( StrLength )
{
if ( Pos < max_length )
{
__MoveCharsToCursor:
;
memcpy( OutStr + Pos, OutStr + Pos + 1, StrLength - Pos );
--StrLength;
++Update;
}
else if ( Pos == max_length )
{
__TruncateAtCursor:
;
OutStr[Pos] = '\0';
StrLength = Pos;
++Update;
}
}
break;
case stExitPlus: /* [Keypad +] -- special exit */
case stExitMinus: /* [Keypad -] -- special exit */
/****
If cursor is beyond the sign position or Sign flag is off,
treat key as an exit; otherwise convert Chr to '+' or '-'
and fall through to the match state.
****/
if ( Pos || !Flags.Sign )
{
hIntegerField( stQuit, 0 );
break;
}
else
Chr = (State == stExitPlus) ? '+' : '-' ;
case stCharMatch: /* see if entry matches field */
if
(
isdigit( Chr )
||
(!Pos && Flags.Sign && (Chr == '-' || Chr == '+'))
)
{
/****
If this is the first entry, clear the field and place
the new character at the beginning.
****/
if ( InBegin )
{
*(WORD *)OutStr = Chr; /* put Chr and '\0' */
Pos = StrLength = 1;
}
else if ( Pos == StrLength )
{
if ( StrLength >= Width )
--StrLength;
*(WORD *)(OutStr + Pos++) = Chr;
++StrLength;
}
else
OutStr[Pos++] = Chr;
++Update;
} /* if (isdigit) */
else
State = stError;
break;
} /* switch */
if ( Pos >= Width )
Pos = Width - 1;
return( Pos );
}
/**** EOF: ININTGR.C ****/